<?php
namespace backend\controllers;
use Yii;
use yii\web\Controller;
use backend\models\ComponyMsg;
use yii\data\Pagination;
use backend\models\Log;
class PositionController extends Controller{

	public $layout = 'common';
	public $enableCsrfValidation = false;

	public function init()
    {
    	parent::init();
    	$session = Yii::$app->session;
    	$session->open();
    	$data=Yii::$app->request->get()['r'];
		// echo $data;die;
		if($data!='login/index')
		{
			if(!isset($_SESSION['user'])){
            echo "<script>alert('请先登录');location.href='?r=login/index'</script>";
        	}
        }
    }
	public function actionShow()
	{
		return $this->render('show');
	}
	public function actionAdd()
	{
		return $this->render('add');
	}

	public function actionCompony()
	{
		
			$query=ComponyMsg::find();
			$pagination = new Pagination([
            'defaultPageSize' => 5,
            'totalCount' => $query->count(),
        	]);

        $countries = $query->orderBy('name')
            ->offset($pagination->offset)
            ->limit($pagination->limit)
            ->all();
		// print_r($model);die;
		return $this->render('compony_lists',['compony'=>$countries,'pagination'=>$pagination]);
		
		
		
	}

	public function actionStatusa()
	{
		// echo "111";
		$data=Yii::$app->request->post();
		// print_r($data);
		$compony = ComponyMsg::findOne($data['id']);
		$compony->status = $data['status'];
		if ($compony->save()) {
			echo json_encode(['val'=>1,'msg'=>'提交成功']);
		}else{
			echo json_encode(['val'=>0,'msg'=>'提交失败']);
		}
		
		// $compony=ComponyMsg::find()->where(['compony_msg_id'=>$id])->one();
		// return $this->render('sta_upd',['compony'=>$compony]);
	}

	
}